package com.yao2san.simdif.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yao2san.simdif.bean.request.HistoryDeleteReq;
import com.yao2san.simdif.bean.request.HistoryListReq;
import com.yao2san.simdif.bean.response.HistoryListRes;
import com.yao2san.simdif.entity.History;
import com.yao2san.simdif.mapper.HistoryMapper;
import com.yao2san.simdif.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class HistoryServiceImpl extends ServiceImpl<HistoryMapper, History> implements HistoryService {

    @Autowired
    private HistoryMapper historyMapper;

    @Override
    public PageInfo<HistoryListRes> list(HistoryListReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        List<HistoryListRes> list = historyMapper.list(req);
        return new PageInfo<>(list);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(HistoryDeleteReq req) {
        if (CollectionUtils.isEmpty(req.getIds())) {
            return;
        }
        this.removeByIds(req.getIds());
    }
}
